/*
 * Copyright 2014 by État de Genève (Switzerland)
 * All rights reserved.
 *
 * Author: ELCA Informatique SA
 */
// this is based on the documentation http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals/
// create a dialog context: dialogContext.js
define(['plugins/dialog'],

    // creates a dialog context to work better with Bootstrap 3 modals
    // BS3 modals add a srollbar when the modal is too big by default.
    // If updating to Durandal 2.1, maybe this is not needed anymore.
    // ref: https://groups.google.com/forum/#!topic/durandaljs/8g7DDCuvlpU
    //      https://gist.github.com/webm0nk3y/7603042

    // Create a dialog using Bootstrap 3
    function(dialog) {
        return {
            addHost: function(theDialog) {
                var body = $('body');
                $('<div class="modal fade" id="myModal"></div>').appendTo(body);
                theDialog.host = $('#myModal').get(0);
            },
            removeHost: function(theDialog) {
                setTimeout(function() {
                    $('#myModal').modal('hide');
                    $('body').removeClass('modal-open');
                    $('.modal-backdrop').remove();
                }, 200);

            },
            compositionComplete: function(child, parent, context) {
                var theDialog = dialog.getDialog(context.model);
                $('#myModal').modal('show');
            }
        };
    });